<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
    

    

    



    <meta charset="utf-8">
    
    
    
    <title>深入理解Java注解 | 奔跑的蜗牛 | 虚心若愚</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    
    <meta name="theme-color" content="#3F51B5">
    
    
    <meta name="keywords" content="Annotation">
    <meta name="description" content="深入理解Java注解1. 什么是注解定义1：注解（也被称为元数据）为我们在代码中添加信息提供了一种形式化的方法，使我们可以在稍后某个时刻非常方便地使用这些数据。（java编程思想） 定义2：Annotation（注解）就是Java提供了一种元程序中的元素关联任何信息和着任何元数据（metadata）的途径和方法。Annotion(注解)是一个接口，程序可以通过反射来获取指定程序元素的Annotio">
<meta name="keywords" content="Annotation">
<meta property="og:type" content="article">
<meta property="og:title" content="深入理解Java注解">
<meta property="og:url" content="http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/index.html">
<meta property="og:site_name" content="奔跑的蜗牛">
<meta property="og:description" content="深入理解Java注解1. 什么是注解定义1：注解（也被称为元数据）为我们在代码中添加信息提供了一种形式化的方法，使我们可以在稍后某个时刻非常方便地使用这些数据。（java编程思想） 定义2：Annotation（注解）就是Java提供了一种元程序中的元素关联任何信息和着任何元数据（metadata）的途径和方法。Annotion(注解)是一个接口，程序可以通过反射来获取指定程序元素的Annotio">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2020-03-18T04:05:43.831Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="深入理解Java注解">
<meta name="twitter:description" content="深入理解Java注解1. 什么是注解定义1：注解（也被称为元数据）为我们在代码中添加信息提供了一种形式化的方法，使我们可以在稍后某个时刻非常方便地使用这些数据。（java编程思想） 定义2：Annotation（注解）就是Java提供了一种元程序中的元素关联任何信息和着任何元数据（metadata）的途径和方法。Annotion(注解)是一个接口，程序可以通过反射来获取指定程序元素的Annotio">
    
        <link rel="alternative" href="/atom.xml" title="奔跑的蜗牛" type="application/atom+xml">
    
    <link rel="shortcut icon" href="/blog/favicon.ico">
    <link rel="stylesheet" href="//unpkg.com/hexo-theme-material-indigo@1.5.2/css/style.css">
    <script>window.lazyScripts=[]</script>
</head>

<body>
    <div id="loading" class="active"></div>

    <aside id="menu" class="hide" >
  <div class="inner flex-row-vertical">
    <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menu-off">
        <i class="icon icon-lg icon-close"></i>
    </a>
    <div class="brand-wrap" style="background-image:url(/blog/img/timg.jpg)">
      <div class="brand">
        <a href="/blog/" class="avatar waves-effect waves-circle waves-light">
          <img src="/blog/img/user2.jpg">
        </a>
        <hgroup class="introduce">
          <h5 class="nickname">windy</h5>
          <a href="mailto:windynature@163.com" title="windynature@163.com" class="mail">windynature@163.com</a>
        </hgroup>
      </div>
    </div>
    <div class="scroll-wrap flex-col">
      <ul class="nav">
        
            <li class="waves-block waves-effect">
              <a href="/blog/"  >
                <i class="icon icon-lg icon-home"></i>
                主页
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/archives"  >
                <i class="icon icon-lg icon-archives"></i>
                归档
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/tags"  >
                <i class="icon icon-lg icon-tags"></i>
                标签
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="/blog/categories"  >
                <i class="icon icon-lg icon-th-list"></i>
                分类
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://github.com/WindyNature" target="_blank" >
                <i class="icon icon-lg icon-github"></i>
                Github
              </a>
            </li>
        
            <li class="waves-block waves-effect">
              <a href="https://git.oschina.net/windynature" target="_blank" >
                <i class="icon icon-lg icon-mayun"></i>
                码云
              </a>
            </li>
        
      </ul>
    </div>
  </div>
</aside>

    <main id="main">
        <header class="top-header" id="header">
    <div class="flex-row">
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light on" id="menu-toggle">
          <i class="icon icon-lg icon-navicon"></i>
        </a>
        <div class="flex-col header-title ellipsis">深入理解Java注解</div>
        
        <div class="search-wrap" id="search-wrap">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="back">
                <i class="icon icon-lg icon-chevron-left"></i>
            </a>
            <input type="text" id="key" class="search-input" autocomplete="off" placeholder="输入感兴趣的关键字">
            <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="search">
                <i class="icon icon-lg icon-search"></i>
            </a>
        </div>
        
        
        <a href="javascript:;" class="header-icon waves-effect waves-circle waves-light" id="menuShare">
            <i class="icon icon-lg icon-share-alt"></i>
        </a>
        
    </div>
</header>
<header class="content-header post-header">

    <div class="container fade-scale">
        <h1 class="title">深入理解Java注解</h1>
        <h5 class="subtitle">
            
                <time datetime="2017-01-26T08:07:00.000Z" itemprop="datePublished" class="page-time">
  2017-01-26
</time>


	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/blog/categories/Java基础/">Java基础</a></li></ul>

            
        </h5>
    </div>

    

</header>


<div class="container body-wrap">
    
    <aside class="post-widget">
        <nav class="post-toc-wrap" id="post-toc">
            <h4>TOC</h4>
            <ol class="post-toc"><li class="post-toc-item post-toc-level-1"><a class="post-toc-link" href="#深入理解Java注解"><span class="post-toc-text">深入理解Java注解</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#1-什么是注解"><span class="post-toc-text">1. 什么是注解</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#2-什么是元数据"><span class="post-toc-text">2. 什么是元数据</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#3-Java内置的注解"><span class="post-toc-text">3. Java内置的注解</span></a></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#4-JDK的元Annotation"><span class="post-toc-text">4. JDK的元Annotation</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#4-1-Target"><span class="post-toc-text">4.1 @Target</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#4-2-Retention"><span class="post-toc-text">4.2 @Retention</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#4-3-Documented"><span class="post-toc-text">4.3 @Documented</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#4-4-Inherited"><span class="post-toc-text">4.4 @Inherited</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#5-自定义注解"><span class="post-toc-text">5. 自定义注解</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#5-1-定义注解格式："><span class="post-toc-text">5.1 定义注解格式：</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#5-2-注解参数的可支持数据类型："><span class="post-toc-text">5.2 注解参数的可支持数据类型：</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#5-3-简单的自定义注解和使用注解实例："><span class="post-toc-text">5.3 简单的自定义注解和使用注解实例：</span></a></li><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#5-4-注解元素的默认值："><span class="post-toc-text">5.4 注解元素的默认值：</span></a></li></ol></li><li class="post-toc-item post-toc-level-2"><a class="post-toc-link" href="#6-注解处理器"><span class="post-toc-text">6. 注解处理器</span></a><ol class="post-toc-child"><li class="post-toc-item post-toc-level-3"><a class="post-toc-link" href="#6-1-注解处理器类库-java-lang-reflect-AnnotatedElement"><span class="post-toc-text">6.1 注解处理器类库(java.lang.reflect.AnnotatedElement)</span></a></li></ol></li></ol></li></ol>
        </nav>
    </aside>
    
<article id="post-java/深入理解Java注解"
  class="post-article article-type-post fade" itemprop="blogPost">

    <div class="post-card">
        <h1 class="post-card-title">深入理解Java注解</h1>
        <div class="post-meta">
            <time class="post-time" title="2017年01月26日 16:07" datetime="2017-01-26T08:07:00.000Z"  itemprop="datePublished">2017-01-26</time>

            
	<ul class="article-category-list"><li class="article-category-list-item"><a class="article-category-list-link" href="/blog/categories/Java基础/">Java基础</a></li></ul>



            
<span id="busuanzi_container_page_pv" title="文章总阅读量" style='display:none'>
    <i class="icon icon-eye icon-pr"></i><span id="busuanzi_value_page_pv"></span>
</span>


            

        </div>
        <div class="post-content" id="post-content" itemprop="postContent">
            <h1 id="深入理解Java注解"><a href="#深入理解Java注解" class="headerlink" title="深入理解Java注解"></a>深入理解Java注解</h1><h2 id="1-什么是注解"><a href="#1-什么是注解" class="headerlink" title="1. 什么是注解"></a>1. 什么是注解</h2><p><strong>定义1：</strong>注解（也被称为元数据）为我们在代码中添加信息提供了一种形式化的方法，使我们可以在稍后某个时刻非常方便地使用这些数据。（java编程思想）</p>
<p><strong>定义2：</strong><code>Annotation</code>（注解）就是Java提供了一种元程序中的元素关联任何信息和着任何元数据（<code>metadata</code>）的途径和方法。<code>Annotion</code>(注解)是一个接口，程序可以通过反射来获取指定程序元素的<code>Annotion</code>对象，然后通过<code>Annotion</code>对象来获取注解里面的元数据。</p>
<p>　　<code>Annotation</code>(注解)是JDK5.0及以后版本引入的。它可以用于创建文档，跟踪代码中的依赖性，甚至执行基本编译时检查。从某些方面看，annotation就像修饰符一样被使用，并应用于<code>包、类 型、构造方法、方法、成员变量、参数、本地变量的声明中。</code>这些信息被存储在Annotation的“name=value”结构对中。</p>
<p>　　<code>Annotation</code>的成员在Annotation类型中以无参数的方法的形式被声明。其方法名和返回值定义了该成员的名字和类型。在此有一个特定的默认语法：允许声明任何Annotation成员的默认值：<strong>一个Annotation可以将name=value对作为没有定义默认值的Annotation成员的值，当然也可以使用name=value对来覆盖其它成员默认值。</strong>这一点有些近似类的继承特性，父类的构造函数可以作为子类的默认构造函数，但是也可以被子类覆盖。</p>
<p>　　<code>Annotation</code>能被用来为某个程序元素（类、方法、成员变量等）关联任何的信息。需要注意的是，这里存在着一个基本的规则：<strong>Annotation不能影响程序代码的执行，无论增加、删除 Annotation，代码都始终如一的执行。</strong>另外，尽管一些annotation通过java的反射api方法在运行时被访问，而java语言解释器在工作时忽略了这些annotation。正是由于java虚拟机忽略了Annotation，导致了annotation类型在代码中是“不起作用”的； 只有通过某种配套的工具才会对annotation类型中的信息进行访问和处理。本文中将涵盖标准的<code>Annotation</code>和<code>meta-annotation</code>类型，陪伴这些annotation类型的工具是java编译器（当然要以某种特殊的方式处理它们）。</p>
<h2 id="2-什么是元数据"><a href="#2-什么是元数据" class="headerlink" title="2. 什么是元数据"></a>2. 什么是元数据</h2><p>元数据从metadata一词译来，就是“关于数据的数据”的意思。</p>
<p>　　元数据的功能作用有很多，比如：你可能用过Javadoc的注释自动生成文档。这就是元数据功能的一种。总的来说，元数据可以用来创建文档，跟踪代码的依赖性，执行编译时格式检查，代替已有的配置文件。如果要对于元数据的作用进行分类，目前还没有明确的定义，不过我们可以根据它所起的作用，大致可分为三类：<br>　　　　1. 编写文档：通过代码里标识的元数据生成文档<br>　　　　2. 代码分析：通过代码里标识的元数据对代码进行分析<br>　　　　3. 编译检查：通过代码里标识的元数据让编译器能实现基本的编译检查<br>　　　　<br>　　在Java中元数据以标签的形式存在于Java代码中，元数据标签的存在并不影响程序代码的编译和执行，它只是被用来生成其它的文件或针在运行时知道被运行代码的描述信息。<br>　　综上所述：<br>　　　　第一，元数据以标签的形式存在于Java代码中。<br>　　　　第二，元数据描述的信息是类型安全的，即元数据内部的字段都是有明确类型的。<br>　　　　第三，元数据需要编译器之外的工具额外的处理用来生成其它的程序部件。<br>　　　　第四，元数据可以只存在于Java源代码级别，也可以存在于编译之后的Class文件内部。</p>
<h2 id="3-Java内置的注解"><a href="#3-Java内置的注解" class="headerlink" title="3. Java内置的注解"></a>3. Java内置的注解</h2><table>
<thead>
<tr>
<th align="left">名称</th>
<th align="left">含义</th>
</tr>
</thead>
<tbody><tr>
<td align="left"><code>@Override</code></td>
<td align="left">表示当前的方法定义将覆盖父类中的方法，如果不小心拼写错误，或者方法签名对不上覆盖的方法，编译器就会发出错误提示。</td>
</tr>
<tr>
<td align="left"><code>@Deprecated</code></td>
<td align="left">用于表示某个程序元素（类、方法等）已过时，当程序使用已过时类、方法时，编译器会给出警告。</td>
</tr>
<tr>
<td align="left"><code>@SuppressWarnings</code></td>
<td align="left">抑制编译器警告，指被修饰的元素（及该程序元素中的所有子元素）取消显示指定的编译器警告</td>
</tr>
</tbody></table>
<h2 id="4-JDK的元Annotation"><a href="#4-JDK的元Annotation" class="headerlink" title="4. JDK的元Annotation"></a>4. JDK的元Annotation</h2><p>元注解的作用激素是负责注解其他注解。<code>Java5.0</code>定义了4个标准的<code>meta-annotation</code>类型，它们用来对其他<code>annotation</code>类型作说明。</p>
<ol>
<li><code>@Target</code></li>
<li><code>@Retention</code></li>
<li><code>@Documented</code></li>
<li><code>@Inherited</code></li>
</ol>
<h3 id="4-1-Target"><a href="#4-1-Target" class="headerlink" title="4.1 @Target"></a>4.1 @Target</h3><p><code>@Target</code>说明了<code>annotation</code>所修饰的对象范围，<code>annotation</code>可被用于packages、types（类、接口、枚举、annotation类型）、类型成员（方法、构造方法、成员变量、枚举值）、方法参数和本地变量（如循环变量、catche参数）。在annotation类型的生命中使用了<code>target</code>可更加明晰其修饰的目标。<br><strong>作用：用于描述注解的使用范围</strong><br><strong>使用实例：</strong></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Target</span>(ElementType.TYPE)</span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> Table &#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 数据表名称注解，默认值为类名称</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">tableName</span><span class="params">()</span> <span class="keyword">default</span> "className"</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Target</span>(ElementType.FIELD)</span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> NoDBColumn &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>注解<code>Table</code>可以用于注解类、接口（包括注解类型）或enum声明，而注解<code>NoDBColumn</code>仅可用于注解类的成员变量。<br>其中<code>ElementType</code>为一个枚举类型，取值如下</p>
<ol>
<li><code>CONSTRUCTOR</code>：用于描述构造器</li>
<li><code>FIELD</code>：用于描述域</li>
<li><code>LOCAL_VARIABLE</code>：用于描述局部变量</li>
<li><code>METHOD</code>：用于描述方法</li>
<li><code>PACKAGE</code>：用于描述包</li>
<li><code>PARAMETER</code>：用于描述参数</li>
<li><code>TYPE</code>：用于描述类、接口(包括注解类型) 或enum声明</li>
<li><code>ANNOTATION_TYPE</code>：用于描述注解类型</li>
</ol>
<h3 id="4-2-Retention"><a href="#4-2-Retention" class="headerlink" title="4.2 @Retention"></a>4.2 @Retention</h3><p><code>@Retention</code>定义了该Annotation被保留的时间长短：某些Annotation仅出现在源代码中，而被编译器丢弃；而另一些却被编译在class文件中；编译在class文件中的Annotation可能会被虚拟机忽略，而另一些在class被装载时将被读取（请注意并不影响class的执行，因为Annotation与class在使用上是被分离的）。使用这个meta-Annotation可以对 Annotation的“生命周期”限制。<br><strong>作用：表示需要在什么级别保存该注释信息，用于描述注解的生命周期（即：被描述的注解在什么范围内有效）</strong><br><code>Retention meta-annotation</code>类型有唯一的<code>value</code>作为成员，它的取值来自<code>java.lang.annotation.RetentionPolicy</code>的枚举类型值。<br>取值（RetentionPoicy）有：</p>
<ol>
<li><code>SOURCE</code>:在源文件中有效（即源文件保留）</li>
<li><code>CLASS</code>:在class文件中有效（即class保留）</li>
<li><code>RUNTIME</code>:在运行时有效（即运行时保留）</li>
</ol>
<p><strong>使用实例:</strong></p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Target</span>(ElementType.FIELD)</span><br><span class="line"><span class="meta">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> Column &#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">name</span><span class="params">()</span> <span class="keyword">default</span> "fieldName"</span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">setFuncName</span><span class="params">()</span> <span class="keyword">default</span> "setField"</span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getFuncName</span><span class="params">()</span> <span class="keyword">default</span> "getField"</span>; </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">defaultDBValue</span><span class="params">()</span> <span class="keyword">default</span> <span class="keyword">false</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>Column注解的的RetentionPolicy的属性值是RUTIME,这样注解处理器可以通过反射，获取到该注解的属性值，从而去做一些运行时的逻辑处理。</p>
<h3 id="4-3-Documented"><a href="#4-3-Documented" class="headerlink" title="4.3 @Documented"></a>4.3 @Documented</h3><p>@Documented用于描述其它类型的<code>annotation</code>应该被作为被标注的程序成员的公共API，因此可以被例如javadoc此类的工具文档化。<code>Documented</code>是一个标记注解，没有成员。</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Target</span>(ElementType.FIELD)</span><br><span class="line"><span class="meta">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> Column &#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">name</span><span class="params">()</span> <span class="keyword">default</span> "fieldName"</span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">setFuncName</span><span class="params">()</span> <span class="keyword">default</span> "setField"</span>;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getFuncName</span><span class="params">()</span> <span class="keyword">default</span> "getField"</span>; </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">defaultDBValue</span><span class="params">()</span> <span class="keyword">default</span> <span class="keyword">false</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="4-4-Inherited"><a href="#4-4-Inherited" class="headerlink" title="4.4 @Inherited"></a>4.4 @Inherited</h3><p>　　<code>@Inherited</code> 元注解是一个标记注解，<code>@Inherited</code>阐述了某个被标注的类型是被继承的。如果一个使用了<code>@Inherited</code>修饰的<code>annotation</code>类型被用于一个<code>class</code>，则这个<code>annotation</code>将被用于该<code>class</code>的子类。</p>
<p>　　注意：<code>@Inherited annotation</code>类型是被标注过的class的子类所继承。类并不从它所实现的接口继承<code>annotation</code>，方法并不从它所重载的方法继承<code>annotation</code>。</p>
<p>　　当<code>@Inherited annotation</code>类型标注的<code>annotation</code>的<code>Retention</code>是<code>RetentionPolicy.RUNTIME</code>，则反射API增强了这种继承性。如果我们使用<code>java.lang.reflect</code>去查询一个<code>@Inherited annotation</code>类型的<code>annotation</code>时，反射代码检查将展开工作：检查class和其父类，直到发现指定的<code>annotation</code>类型被发现，或者到达类继承结构的顶层。
　　</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="meta">@Inherited</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> Greeting &#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">enum</span> FontColor&#123; BULE,RED,GREEN&#125;;</span><br><span class="line">    <span class="function">String <span class="title">name</span><span class="params">()</span></span>;</span><br><span class="line">    <span class="function">FontColor <span class="title">fontColor</span><span class="params">()</span> <span class="keyword">default</span> FontColor.GREEN</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="5-自定义注解"><a href="#5-自定义注解" class="headerlink" title="5. 自定义注解"></a>5. 自定义注解</h2><p>使用<code>@interface</code>自定义注解时，自动继承了<code>java.lang.annotation.Annotation</code>接口，由编译程序自动完成其他细节。在定义注解时，不能继承其他的注解或接口。<code>@interface</code>用来声明一个注解，其中的每一个方法实际上是声明了一个配置参数。方法的名称就是参数的名称，返回值类型就是参数的类型（返回值类型只能是基本类型、<code>Class</code>、<code>String</code>、<code>enum</code>）。可以通过<code>default</code>来声明参数的默认值。</p>
<h3 id="5-1-定义注解格式："><a href="#5-1-定义注解格式：" class="headerlink" title="5.1 定义注解格式："></a>5.1 定义注解格式：</h3><p><code>public @interface</code> 注解名 {定义体}</p>
<h3 id="5-2-注解参数的可支持数据类型："><a href="#5-2-注解参数的可支持数据类型：" class="headerlink" title="5.2 注解参数的可支持数据类型："></a>5.2 注解参数的可支持数据类型：</h3><ol>
<li>所有基本数据类型（<code>int,float,boolean,byte,double,char,long,short</code>)</li>
<li><code>String</code>类型</li>
<li><code>Class</code>类型</li>
<li><code>enum</code>类型</li>
<li><code>Annotation</code>类型</li>
<li>以上所有类型的数组</li>
</ol>
<p><code>Annotation</code>类型里面的参数该怎么设定:<br>　　第一,只能用<code>public</code>或默认(<code>default</code>)这两个访问权修饰.例如,<code>String value()</code>;这里把方法设为defaul默认类型；<br>　　第二,参数成员只能用基本类型<code>byte,short,char,int,long,float,double,boolean</code>八种基本数据类型和 <code>String,Enum,Class,annotations</code>等数据类型,以及这一些类型的数组.例如,<code>String value()</code>;这里的参数成员就为<code>String</code>;　　<br>　　第三,如果只有一个参数成员,最好把参数名称设为<code>&quot;value&quot;</code>,后加小括号.例:下面的例子FruitName注解就只有一个参数成员。</p>
<h3 id="5-3-简单的自定义注解和使用注解实例："><a href="#5-3-简单的自定义注解和使用注解实例：" class="headerlink" title="5.3 简单的自定义注解和使用注解实例："></a>5.3 简单的自定义注解和使用注解实例：</h3><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">package</span> annotation;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Documented;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.ElementType;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Retention;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.RetentionPolicy;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Target;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 水果名称注解</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Target</span>(ElementType.FIELD)</span><br><span class="line"><span class="meta">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> FruitName &#123;</span><br><span class="line">    <span class="function">String <span class="title">value</span><span class="params">()</span> <span class="keyword">default</span> ""</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">package</span> annotation;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Documented;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.ElementType;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Retention;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.RetentionPolicy;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Target;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 水果颜色注解</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Target</span>(ElementType.FIELD)</span><br><span class="line"><span class="meta">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> FruitColor &#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 颜色枚举</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@author</span> peida</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">enum</span> Color&#123; BULE,RED,GREEN&#125;;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 颜色属性</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function">Color <span class="title">fruitColor</span><span class="params">()</span> <span class="keyword">default</span> Color.GREEN</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">package</span> annotation;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> annotation.FruitColor.Color;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Apple</span> </span>&#123;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@FruitName</span>(<span class="string">"Apple"</span>)</span><br><span class="line">    <span class="keyword">private</span> String appleName;</span><br><span class="line">    </span><br><span class="line">    <span class="meta">@FruitColor</span>(fruitColor=Color.RED)</span><br><span class="line">    <span class="keyword">private</span> String appleColor;</span><br><span class="line">     </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setAppleColor</span><span class="params">(String appleColor)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.appleColor = appleColor;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getAppleColor</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> appleColor;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setAppleName</span><span class="params">(String appleName)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">this</span>.appleName = appleName;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getAppleName</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> appleName;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">displayName</span><span class="params">()</span></span>&#123;</span><br><span class="line">        System.out.println(<span class="string">"水果的名字是：苹果"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="5-4-注解元素的默认值："><a href="#5-4-注解元素的默认值：" class="headerlink" title="5.4 注解元素的默认值："></a>5.4 注解元素的默认值：</h3><p>　　注解元素必须有确定的值，要么在定义注解的默认值中指定，要么在使用注解时指定，非基本类型的注解元素的值不可为null。因此, 使用空字符串或0作为默认值是一种常用的做法。这个约束使得处理器很难表现一个元素的存在或缺失的状态，因为每个注解的声明中，所有元素都存在，并且都具有相应的值，为了绕开这个约束，我们只能定义一些特殊的值，例如空字符串或者负数，一次表示某个元素不存在，在定义注解时，这已经成为一个习惯用法。例如：
　　</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="keyword">package</span> annotation;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Documented;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.ElementType;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Retention;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.RetentionPolicy;</span><br><span class="line"><span class="keyword">import</span> java.lang.annotation.Target;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 水果供应者注解</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> peida</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Target</span>(ElementType.FIELD)</span><br><span class="line"><span class="meta">@Retention</span>(RetentionPolicy.RUNTIME)</span><br><span class="line"><span class="meta">@Documented</span></span><br><span class="line"><span class="keyword">public</span> <span class="meta">@interface</span> FruitProvider &#123;</span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 供应商编号</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">id</span><span class="params">()</span> <span class="keyword">default</span> -1</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 供应商名称</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">name</span><span class="params">()</span> <span class="keyword">default</span> ""</span>;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 供应商地址</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">address</span><span class="params">()</span> <span class="keyword">default</span> ""</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>定义了注解，并在需要的时候给相关类，类属性加上注解信息，如果没有响应的注解信息处理流程，注解可以说是没有实用价值。如何让注解真真的发挥作用，主要就在于注解处理方法，下一步我们将学习注解信息的获取和处理！</p>
<h2 id="6-注解处理器"><a href="#6-注解处理器" class="headerlink" title="6. 注解处理器"></a>6. 注解处理器</h2><p>如果没有用来读取注解的方法和工作，那么注解也就不会比注释更有用处了。使用注解的过程中，很重要的一部分就是创建于使用注解处理器。Java SE5扩展了反射机制的API，以帮助程序员快速的构造自定义注解处理器。</p>
<h3 id="6-1-注解处理器类库-java-lang-reflect-AnnotatedElement"><a href="#6-1-注解处理器类库-java-lang-reflect-AnnotatedElement" class="headerlink" title="6.1 注解处理器类库(java.lang.reflect.AnnotatedElement)"></a>6.1 注解处理器类库(<code>java.lang.reflect.AnnotatedElement</code>)</h3><p>Java使用Annotation接口来代表程序元素前面的注解，该接口是所有Annotation类型的父接口。除此之外，Java在<code>java.lang.reflect</code>包下新增了AnnotatedElement接口，该接口代表程序中可以接受注解的程序元素，该接口主要有如下几个实现类：</p>
<ul>
<li><code>Class</code>：类定义</li>
<li><code>Constructor</code>：构造器定义</li>
<li><code>Field</code>：累的成员变量定义</li>
<li><code>Method</code>：类的方法定义</li>
<li><code>Package</code>：类的包定义</li>
</ul>
<p>　　<code>java.lang.reflect</code> 包下主要包含一些实现反射功能的工具类，实际上，java.lang.reflect 包所有提供的反射API扩充了读取运行时Annotation信息的能力。当一个Annotation类型被定义为运行时的Annotation后，该注解才能是运行时可见，当class文件被装载时被保存在class文件中的Annotation才会被虚拟机读取。<br>　　<code>AnnotatedElement</code> 接口是所有程序元素<code>（Class、Method和Constructor）</code>的父接口，所以程序通过反射获取了某个类的<code>AnnotatedElement</code>对象之后，程序就可以调用该对象的如下四个个方法来访问Annotation信息：</p>
<ul>
<li>方法1：<code>&lt;T extends Annotation&gt; T getAnnotation(Class&lt;T&gt; annotationClass)</code>: 返回改程序元素上存在的、指定类型的注解，如果该类型注解不存在，则返回null。</li>
<li>方法2：<code>Annotation[] getAnnotations()</code>:返回该程序元素上存在的所有注解。</li>
<li>方法3：<code>boolean is AnnotationPresent(Class&lt;?extends Annotation&gt; annotationClass)</code>:判断该程序元素上是否包含指定类型的注解，存在则返回true，否则返回false.</li>
<li>方法4：<code>Annotation[] getDeclaredAnnotations()</code>：返回直接存在于此元素上的所有注释。与此接口中的其他方法不同，该方法将忽略继承的注释。（如果没有注释直接存在于此元素上，则返回长度为零的一个数组。）该方法的调用者可以随意修改返回的数组；这不会对其他调用者返回的数组产生任何影响。</li>
</ul>
<p>一个简单的注解处理器：</p>
<figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="comment">//注解处理器</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FruitInfoUtil</span> </span>&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">getFruitInfo</span><span class="params">(Class&lt;?&gt; clazz)</span></span>&#123;</span><br><span class="line">        </span><br><span class="line">        String strFruitName=<span class="string">" 水果名称："</span>;</span><br><span class="line">        String strFruitColor=<span class="string">" 水果颜色："</span>;</span><br><span class="line">        String strFruitProvicer=<span class="string">"供应商信息："</span>;</span><br><span class="line">        </span><br><span class="line">        Field[] fields = clazz.getDeclaredFields();</span><br><span class="line">        </span><br><span class="line">        <span class="keyword">for</span>(Field field :fields)&#123;</span><br><span class="line">            <span class="keyword">if</span>(field.isAnnotationPresent(FruitName<span class="class">.<span class="keyword">class</span>))</span>&#123;</span><br><span class="line">                FruitName fruitName = (FruitName) field.getAnnotation(FruitName<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">                strFruitName=strFruitName+fruitName.value();</span><br><span class="line">                System.out.println(strFruitName);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span>(field.isAnnotationPresent(FruitColor<span class="class">.<span class="keyword">class</span>))</span>&#123;</span><br><span class="line">                FruitColor fruitColor= (FruitColor) field.getAnnotation(FruitColor<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">                strFruitColor=strFruitColor+fruitColor.fruitColor().toString();</span><br><span class="line">                System.out.println(strFruitColor);</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span> <span class="keyword">if</span>(field.isAnnotationPresent(FruitProvider<span class="class">.<span class="keyword">class</span>))</span>&#123;</span><br><span class="line">                FruitProvider fruitProvider= (FruitProvider) field.getAnnotation(FruitProvider<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">                strFruitProvicer=<span class="string">" 供应商编号："</span>+fruitProvider.id()+<span class="string">" 供应商名称："</span>+fruitProvider.name()+<span class="string">" 供应商地址："</span>+fruitProvider.address();</span><br><span class="line">                System.out.println(strFruitProvicer);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">/***********输出结果***************/</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">FruitRun</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        </span><br><span class="line">        FruitInfoUtil.getFruitInfo(Apple<span class="class">.<span class="keyword">class</span>)</span>;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><a href="http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html" target="_blank" rel="noopener">【3,4节出处：】http://www.cnblogs.com/peida/archive/2013/04/24/3036689.html</a></p>

        </div>

        <blockquote class="post-copyright">
    <div class="content">
        
<span class="post-time">
    最后更新时间：<time datetime="2020-03-18T04:05:43.831Z" itemprop="dateUpdated">2020年3月18日 12:05</time>
</span><br>


        这里写留言或版权声明：<a href="/blog/2017/01/26/java/深入理解Java注解/" target="_blank" rel="external">http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/</a>
    </div>
    <footer>
        <a href="http://windynature.oschina.io">
            <img src="/blog/img/user2.jpg" alt="windy">
            windy
        </a>
    </footer>
</blockquote>

        


        <div class="post-footer">
            
	<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/Annotation/">Annotation</a></li></ul>


            
<div class="page-share-wrap">
    

<div class="page-share" id="pageShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/&title=《深入理解Java注解》 — 奔跑的蜗牛&pic=http://windynature.oschina.io/img/user2.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/&title=《深入理解Java注解》 — 奔跑的蜗牛&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《深入理解Java注解》 — 奔跑的蜗牛&url=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/&via=http://windynature.oschina.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>



    <a href="javascript:;" id="shareFab" class="page-share-fab waves-effect waves-circle">
        <i class="icon icon-share-alt icon-lg"></i>
    </a>
</div>



        </div>
    </div>

    
<nav class="post-nav flex-row flex-justify-between">
  
    <div class="waves-block waves-effect prev">
      <a href="/blog/2017/01/26/工具/git远程操作详解/" id="post-prev" class="post-nav-link">
        <div class="tips"><i class="icon icon-angle-left icon-lg icon-pr"></i> Prev</div>
        <h4 class="title">Git远程操作详解</h4>
      </a>
    </div>
  

  
    <div class="waves-block waves-effect next">
      <a href="/blog/2017/01/26/java/一、用户管理/" id="post-next" class="post-nav-link">
        <div class="tips">Next <i class="icon icon-angle-right icon-lg icon-pl"></i></div>
        <h4 class="title">rabbitMQ 用户管理</h4>
      </a>
    </div>
  
</nav>



    

<div class="comments" id="comments">
    <div class="ds-thread" data-thread-key="java/深入理解Java注解" data-title="深入理解Java注解" data-url="http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/"></div>
</div>
<script>
lazyScripts.push('//cdn.bootcss.com/marked/0.3.6/marked.min.js');

var duoshuoQuery = {short_name:'ysblog', theme: 'none'};
lazyScripts.push('//unpkg.com/hexo-theme-material-indigo@1.5.2/js/embed.min.js');


</script>










</article>



</div>

        <footer class="footer">
    <div class="top">
        
<p>
    <span id="busuanzi_container_site_uv" style='display:none'>
        站点总访客数：<span id="busuanzi_value_site_uv"></span>
    </span>
    <span id="busuanzi_container_site_pv" style='display:none'>
        站点总访问量：<span id="busuanzi_value_site_pv"></span>
    </span>
</p>


        <p>
            <span><a href="/atom.xml" target="_blank" class="rss" title="rss"><i class="icon icon-lg icon-rss"></i></a></span>
            <span>博客内容遵循 <a href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">知识共享 署名 - 非商业性 - 相同方式共享 4.0协议</a></span>
        </p>
    </div>
    <div class="bottom">
        <p>
            <span>Power by <a href="http://hexo.io/" target="_blank">Hexo</a> Theme <a href="https://github.com/yscoder/hexo-theme-indigo" target="_blank">indigo</a></span>
            <span>奔跑的蜗牛 &copy; 2015 - 2020</span>
        </p>
    </div>
</footer>

    </main>
    <div class="mask" id="mask"></div>
<a href="javascript:;" id="gotop" class="waves-effect waves-circle waves-light"><span class="icon icon-lg icon-chevron-up"></span></a>



<div class="global-share" id="globalShare">
    <ul class="reset share-icons">
      <li>
        <a class="weibo share-sns" target="_blank" href="http://service.weibo.com/share/share.php?url=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/&title=《深入理解Java注解》 — 奔跑的蜗牛&pic=http://windynature.oschina.io/img/user2.jpg" data-title="微博">
          <i class="icon icon-weibo"></i>
        </a>
      </li>
      <li>
        <a class="weixin share-sns wxFab" href="javascript:;" data-title="微信">
          <i class="icon icon-weixin"></i>
        </a>
      </li>
      <li>
        <a class="qq share-sns" target="_blank" href="http://connect.qq.com/widget/shareqq/index.html?url=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/&title=《深入理解Java注解》 — 奔跑的蜗牛&source=" data-title=" QQ">
          <i class="icon icon-qq"></i>
        </a>
      </li>
      <li>
        <a class="facebook share-sns" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/" data-title=" Facebook">
          <i class="icon icon-facebook"></i>
        </a>
      </li>
      <li>
        <a class="twitter share-sns" target="_blank" href="https://twitter.com/intent/tweet?text=《深入理解Java注解》 — 奔跑的蜗牛&url=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/&via=http://windynature.oschina.io" data-title=" Twitter">
          <i class="icon icon-twitter"></i>
        </a>
      </li>
      <li>
        <a class="google share-sns" target="_blank" href="https://plus.google.com/share?url=http://windynature.oschina.io/2017/01/26/java/深入理解Java注解/" data-title=" Google+">
          <i class="icon icon-google-plus"></i>
        </a>
      </li>
    </ul>
 </div>


<div class="page-modal wx-share" id="wxShare">
    <a class="close" href="javascript:;"><i class="icon icon-close"></i></a>
    <p>扫一扫，分享到微信</p>
    <img src="" alt="微信分享二维码">
</div>




    <script src="//cdn.bootcss.com/node-waves/0.7.4/waves.min.js"></script>
<script>
var BLOG = { ROOT: '/blog/', SHARE: true, REWARD: false };



</script>

<script src="//unpkg.com/hexo-theme-material-indigo@1.5.2/js/main.min.js"></script>


<div class="search-panel" id="search-panel">
    <ul class="search-result" id="search-result"></ul>
</div>
<template id="search-tpl">
<li class="item">
    <a href="{path}" class="waves-block waves-effect">
        <div class="title ellipsis" title="{title}">{title}</div>
        <div class="flex-row flex-middle">
            <div class="tags ellipsis">
                {tags}
            </div>
            <time class="flex-col time">{date}</time>
        </div>
    </a>
</li>
</template>

<script src="//unpkg.com/hexo-theme-material-indigo@1.5.2/js/search.min.js" async></script>






<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
